package src.test.client.presenter;

import src.test.client.service.ServiceFacade;
import src.test.shared.Persona;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public class personPresenter {
	public interface PersonInterView{
		Button getSendButton();
		Label getTextBox1();

	}

	private  PersonInterView view;
	public personPresenter(PersonInterView view){
		this.view = view;
		init();
		
	}
	private void init() {
		// TODO Auto-generated method stub
		
		view.getSendButton().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				// TODO Auto-generated method stub
			
				
				
				//servicio 
				ServiceFacade.getTestService().getPersona( new AsyncCallback<Persona>() {
					
					@Override
					public void onSuccess(Persona result) {
						// TODO Auto-generated method stub
						view.getTextBox1().setText(result.getApellido() + result.getNombre());
					}
					
					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub
						GWT.log(caught.getLocalizedMessage());
					}
				});
			}
		});
		
	}
	public PersonInterView getView() {
		return view;
	}

}
